package com.example.demo.ImgTest;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.image.v2.region.ImageRegion;
import com.huaweicloud.sdk.image.v2.*;
import com.huaweicloud.sdk.image.v2.model.*;

/**
 * 媒资图像标签(检测)
 *
 * 对用户传入的图像可以返回图像中物体的坐标位置、物体名称、所属类别及置信度信息。
 */
public class HuaWeiImgC {

    public static void main(String[] args) {
        // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险，建议在配置文件或者环境变量中密文存放，使用时解密，确保安全
        // 本示例以ak和sk保存在环境变量中来实现身份验证为例，运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK
        String ak = "D4V7FPPVAS2W3YRJSPYF";
        String sk = "dKmJyVJtxe4zn3mfvVVgTpSqtQB36MADe8H4reSz";

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        ImageClient client = ImageClient.newBuilder()
                .withCredential(auth)
                .withRegion(ImageRegion.valueOf("cn-north-4"))
                .build();

//        RunImageMediaTaggingDetRequest request = new RunImageMediaTaggingDetRequest();
//
//        request.withBody(body);
//        try {
//            RunImageMediaTaggingDetResponse response = client.runImageMediaTaggingDet(request);
//            System.out.println(response.toString());
//        } catch (ConnectionException e) {
//            e.printStackTrace();
//        } catch (RequestTimeoutException e) {
//            e.printStackTrace();
//        } catch (ServiceResponseException e) {
//            e.printStackTrace();
//            System.out.println(e.getHttpStatusCode());
//            System.out.println(e.getRequestId());
//            System.out.println(e.getErrorCode());
//            System.out.println(e.getErrorMsg());
//        }
    }
}
